#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL fj[maxn],fo[maxn],gj[maxn],go[maxn];
LL a[maxn],siz[maxn];
LL n,ans=0;
vector<LL>g[maxn];
void dfs1(LL u,LL fa){
     siz[u]=1;fj[u]=0;fo[u]=1;
     for(LL i=0;i<g[u].size();i++){
         LL v=g[u][i];
         if(v==fa) continue;
         dfs1(v,u);
         fj[u]+=fo[v];
         fo[u]+=fj[v];
         siz[u]+=siz[v];
     }
     ans=(ans%mod+a[u]%mod*(fo[u]-fj[u])%mod*(n-siz[u]+1)%mod)%mod;
     for(LL i=0;i<g[u].size();i++){
         LL v=g[u][i];
         if(v==fa) continue;
         ans=(ans%mod+a[u]*(fj[v]-fo[v])%mod*(siz[u]-siz[v]-1)%mod)%mod;
     }
     ans=(ans%mod+a[u]%mod*(siz[u]-1)%mod)%mod;
}
void dfs2(LL u,LL fa){
     if(fa){
        go[u]=gj[fa]+fj[fa]-fo[u];
        gj[u]=go[fa]+fo[fa]-fj[u];
     }
     for(LL i=0;i<g[u].size();i++){
         LL v=g[u][i];
         if(v==fa) continue;
         dfs2(v,u);
     }
     ans=(ans%mod+a[u]%mod*(go[u]-gj[u])*siz[u]%mod)%mod;

}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   cin>>n;
   for(LL i=1;i<=n;i++) cin>>a[i];
   for(LL i=1;i<n;i++){
       LL u,v;cin>>u>>v;
       g[u].push_back(v);
       g[v].push_back(u);
   }
   dfs1(1,0);
   dfs2(1,0);
   cout<<(ans%mod+mod)%mod<<"\n";
   return 0;
}
